{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "l3kzG83yPRHX"
   },
   "source": [
    "# AI Code Generation System: Multi-Agent Programming Assistant with PraisonAI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "BozAlx2dPS3Y"
   },
   "source": [
    "An intelligent code generation system that creates specialized programming code from natural language descriptions. Features multiple AI agents for code generation, debugging, validation, and updates. Built with PraisonAI framework, it demonstrates advanced multi-agent collaboration for software development workflows. Perfect for rapid prototyping, educational content creation, and automated code generation across various programming domains."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "I9UqNin7PanL"
   },
   "source": [
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/intelligent_programming_agent.ipynb)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "trQTNYiHO1mi",
    "outputId": "913e1419-c8de-49e4-d2ef-e02c0f0bea2c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📦 Dependencies installed successfully!\n",
      "🎬 Manim Code Generator ready!\n",
      "🤖 Using PraisonAI Multi-Agent Framework\n",
      "💡 Note: This generates Manim code only (no video rendering)\n"
     ]
    }
   ],
   "source": [
    "# @title **📦 Install Dependencies**\n",
    "\n",
    "# Install only essential packages\n",
    "!pip install praisonaiagents -q\n",
    "!pip install openai -q\n",
    "!pip install python-dotenv -q\n",
    "\n",
    "# Basic imports\n",
    "import os\n",
    "import json\n",
    "import tempfile\n",
    "import shutil\n",
    "import logging\n",
    "import subprocess\n",
    "import re\n",
    "from pathlib import Path\n",
    "from typing import Dict, List, Optional, Any, Tuple\n",
    "from datetime import datetime\n",
    "import getpass\n",
    "\n",
    "print(\"📦 Dependencies installed successfully!\")\n",
    "print(\"🎬 Manim Code Generator ready!\")\n",
    "print(\"🤖 Using PraisonAI Multi-Agent Framework\")\n",
    "print(\"💡 Note: This generates Manim code only (no video rendering)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "bL_IuGP4O7Ua",
    "outputId": "24095118-2a75-4814-af3c-13b2245331b1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "🔑 OpenAI API Key Setup\n",
      "Enter your OpenAI API key:\n",
      "OpenAI API Key: ··········\n",
      "✅ API key configured!\n",
      "🚀 Ready to generate Manim code!\n"
     ]
    }
   ],
   "source": [
    "# @title ** Set OpenAI API Key**\n",
    "\n",
    "# Set up API key\n",
    "print(\"🔑 OpenAI API Key Setup\")\n",
    "print(\"Enter your OpenAI API key:\")\n",
    "\n",
    "api_key = getpass.getpass(\"OpenAI API Key: \")\n",
    "\n",
    "if not api_key or api_key.strip() == \"\":\n",
    "    print(\"⚠️  No API key provided. Using demo mode with mock responses.\")\n",
    "    api_key = \"demo-key\"\n",
    "\n",
    "# Set environment variable\n",
    "os.environ[\"OPENAI_API_KEY\"] = api_key\n",
    "\n",
    "print(\"✅ API key configured!\")\n",
    "print(\"🚀 Ready to generate Manim code!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "fe0hQYhRO_VJ",
    "outputId": "5ed3217a-d505-4795-c94b-c0e96d04f7e4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ Custom Manim code tools initialized!\n"
     ]
    }
   ],
   "source": [
    "# @title **️ Custom Code Tools**\n",
    "\n",
    "class ManimCodeTools:\n",
    "    \"\"\"Custom tools for Manim code generation and validation\"\"\"\n",
    "\n",
    "    @staticmethod\n",
    "    def clean_manim_code(code: str) -> str:\n",
    "        \"\"\"Clean and format Manim code\"\"\"\n",
    "        # Remove markdown code blocks if present\n",
    "        if \"```python\" in code:\n",
    "            code = code.split(\"```python\")[1]\n",
    "        if \"```\" in code:\n",
    "            code = code.split(\"```\")[0]\n",
    "\n",
    "        # Clean up extra whitespace\n",
    "        code = code.strip()\n",
    "        return code\n",
    "\n",
    "    @staticmethod\n",
    "    def extract_scene_class_name(code: str) -> str:\n",
    "        \"\"\"Extract scene class name from Manim code\"\"\"\n",
    "        # Look for class definitions that inherit from Scene\n",
    "        pattern = r'class\\s+(\\w+)\\s*\\(.*Scene.*\\):'\n",
    "        match = re.search(pattern, code)\n",
    "        if match:\n",
    "            return match.group(1)\n",
    "\n",
    "        # Fallback: look for any class definition\n",
    "        pattern = r'class\\s+(\\w+)\\s*:'\n",
    "        match = re.search(pattern, code)\n",
    "        if match:\n",
    "            return match.group(1)\n",
    "\n",
    "        return \"\"\n",
    "\n",
    "    @staticmethod\n",
    "    def validate_python_syntax(code: str) -> Tuple[bool, str]:\n",
    "        \"\"\"Validate Python syntax without executing\"\"\"\n",
    "        try:\n",
    "            compile(code, '<string>', 'exec')\n",
    "            return True, \"Syntax is valid\"\n",
    "        except SyntaxError as e:\n",
    "            return False, f\"Syntax error: {str(e)}\"\n",
    "        except Exception as e:\n",
    "            return False, f\"Validation error: {str(e)}\"\n",
    "\n",
    "    @staticmethod\n",
    "    def check_manim_imports(code: str) -> Tuple[bool, str]:\n",
    "        \"\"\"Check if Manim imports are present\"\"\"\n",
    "        required_imports = ['from manim import', 'import manim']\n",
    "        found_imports = []\n",
    "\n",
    "        for import_line in required_imports:\n",
    "            if import_line in code:\n",
    "                found_imports.append(import_line)\n",
    "\n",
    "        if found_imports:\n",
    "            return True, f\"Found Manim imports: {', '.join(found_imports)}\"\n",
    "        else:\n",
    "            return False, \"No Manim imports found\"\n",
    "\n",
    "    @staticmethod\n",
    "    def check_scene_class(code: str) -> Tuple[bool, str]:\n",
    "        \"\"\"Check if Scene class is properly defined\"\"\"\n",
    "        scene_pattern = r'class\\s+\\w+\\s*\\(.*Scene.*\\):'\n",
    "        if re.search(scene_pattern, code):\n",
    "            return True, \"Scene class found\"\n",
    "        else:\n",
    "            return False, \"No Scene class found\"\n",
    "\n",
    "    @staticmethod\n",
    "    def generate_code_summary(code: str) -> Dict[str, Any]:\n",
    "        \"\"\"Generate a summary of the code\"\"\"\n",
    "        scene_name = ManimCodeTools.extract_scene_class_name(code)\n",
    "        syntax_valid, syntax_msg = ManimCodeTools.validate_python_syntax(code)\n",
    "        imports_ok, imports_msg = ManimCodeTools.check_manim_imports(code)\n",
    "        scene_ok, scene_msg = ManimCodeTools.check_scene_class(code)\n",
    "\n",
    "        return {\n",
    "            \"scene_name\": scene_name,\n",
    "            \"syntax_valid\": syntax_valid,\n",
    "            \"syntax_message\": syntax_msg,\n",
    "            \"imports_ok\": imports_ok,\n",
    "            \"imports_message\": imports_msg,\n",
    "            \"scene_ok\": scene_ok,\n",
    "            \"scene_message\": scene_msg,\n",
    "            \"code_length\": len(code),\n",
    "            \"lines\": len(code.split('\\n'))\n",
    "        }\n",
    "\n",
    "# Initialize tools\n",
    "manim_tools = ManimCodeTools()\n",
    "print(\"✅ Custom Manim code tools initialized!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000,
     "referenced_widgets": [
      "5a67a4a41d0d48d3870a3c1eb967493b",
      "f748833f06464214a9d4e7cf0cec7a68"
     ]
    },
    "id": "zsrklVrjPCFU",
    "outputId": "6327299f-416a-4f68-8b13-a9813e6528ad"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " AI Manim Code Generator Ready!\n",
      "============================================================\n",
      "🚀 Demo: Generating Manim code...\n",
      "🎬 Generating Manim code for: 'Create an animation showing a circle moving in a sine wave pattern'\n",
      "============================================================\n",
      "�� Step 1: Generating Manim code...\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╭─ </span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8; font-weight: bold\">Agent Info</span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\"> ────────────────────────────────────────────────────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #ff9b9b; text-decoration-color: #ff9b9b; font-weight: bold\">👤 Agent:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Manim Code Generator</span>                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #b4b4b3; text-decoration-color: #b4b4b3; font-weight: bold\">Role:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Complete Manim Animation Specialist</span>                                                                      <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[38;2;210;227;200m╭─\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[1;38;2;210;227;200mAgent Info\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[38;2;210;227;200m───────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;210;227;200m─╮\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;255;155;155m👤 Agent:\u001b[0m \u001b[38;2;255;229;229mManim Code Generator\u001b[0m                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;180;180;179mRole:\u001b[0m \u001b[38;2;255;229;229mComplete Manim Animation Specialist\u001b[0m                                                                      \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5a67a4a41d0d48d3870a3c1eb967493b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">Response generated in 7.6s</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2mResponse generated in 7.6s\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭───────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> You need to do the following task: Generate high-quality Manim code for this animation request: Create an       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> animation showing a circle moving in a sine wave pattern                                                        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    Requirements:</span><span style=\"background-color: #272822\">                                                                                             </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Create a class that inherits from Scene</span><span style=\"background-color: #272822\">                                                                 </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Include proper imports (from manim import *)</span><span style=\"background-color: #272822\">                                                            </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Use descriptive class names</span><span style=\"background-color: #272822\">                                                                             </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Include a construct method with self.play() calls</span><span style=\"background-color: #272822\">                                                       </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Add comments for clarity</span><span style=\"background-color: #272822\">                                                                                </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Ensure code is complete and runnable</span><span style=\"background-color: #272822\">                                                                    </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Follow Manim best practices</span><span style=\"background-color: #272822\">                                                                             </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Handle mathematical concepts properly</span><span style=\"background-color: #272822\">                                                                   </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    - Use appropriate animation timing</span><span style=\"background-color: #272822\">                                                                        </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    .</span><span style=\"background-color: #272822\">                                                                                                         </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> Expected Output: Complete the task successfully. Please provide only the final result of your work. Do not add  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> any conversation or extra explanation.                                                                          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m────────────────────────────────────────────────────\u001b[0m\u001b[36m Task \u001b[0m\u001b[36m─────────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m You need to do the following task: Generate high-quality Manim code for this animation request: Create an       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m animation showing a circle moving in a sine wave pattern                                                        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    Requirements:\u001b[0m\u001b[48;2;39;40;34m                                                                                            \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Create a class that inherits from Scene\u001b[0m\u001b[48;2;39;40;34m                                                                \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Include proper imports (from manim import *)\u001b[0m\u001b[48;2;39;40;34m                                                           \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Use descriptive class names\u001b[0m\u001b[48;2;39;40;34m                                                                            \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Include a construct method with self.play() calls\u001b[0m\u001b[48;2;39;40;34m                                                      \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Add comments for clarity\u001b[0m\u001b[48;2;39;40;34m                                                                               \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Ensure code is complete and runnable\u001b[0m\u001b[48;2;39;40;34m                                                                   \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Follow Manim best practices\u001b[0m\u001b[48;2;39;40;34m                                                                            \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Handle mathematical concepts properly\u001b[0m\u001b[48;2;39;40;34m                                                                  \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    - Use appropriate animation timing\u001b[0m\u001b[48;2;39;40;34m                                                                       \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    .\u001b[0m\u001b[48;2;39;40;34m                                                                                                        \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m Expected Output: Complete the task successfully. Please provide only the final result of your work. Do not add  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m any conversation or extra explanation.                                                                          \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭─────────────────────────────────────────────────── Response ────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">from</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> manim </span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">import</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> </span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">*</span><span style=\"background-color: #272822\">                                                                                           </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #66d9ef; text-decoration-color: #66d9ef; background-color: #272822\">class</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> </span><span style=\"color: #a6e22e; text-decoration-color: #a6e22e; background-color: #272822\">CircleSineWave</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">(Scene):</span><span style=\"background-color: #272822\">                                                                                  </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">    </span><span style=\"color: #66d9ef; text-decoration-color: #66d9ef; background-color: #272822\">def</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> </span><span style=\"color: #a6e22e; text-decoration-color: #a6e22e; background-color: #272822\">construct</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">(self):</span><span style=\"background-color: #272822\">                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"color: #959077; text-decoration-color: #959077; background-color: #272822\"># Create a circle</span><span style=\"background-color: #272822\">                                                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        circle </span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> Circle(radius</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #ae81ff; text-decoration-color: #ae81ff; background-color: #272822\">0.2</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">, color</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">BLUE)</span><span style=\"background-color: #272822\">                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"background-color: #272822\">                                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"color: #959077; text-decoration-color: #959077; background-color: #272822\"># Define the sine wave path</span><span style=\"background-color: #272822\">                                                                           </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        sine_wave_path </span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> ParametricFunction(</span><span style=\"background-color: #272822\">                                                                  </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">            </span><span style=\"color: #66d9ef; text-decoration-color: #66d9ef; background-color: #272822\">lambda</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\"> t: np</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">array([t, np</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">sin(t), </span><span style=\"color: #ae81ff; text-decoration-color: #ae81ff; background-color: #272822\">0</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">]),</span><span style=\"background-color: #272822\">                                                            </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">            t_range</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">np</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">array([</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">-</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">PI, PI, </span><span style=\"color: #ae81ff; text-decoration-color: #ae81ff; background-color: #272822\">0.01</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">]),</span><span style=\"background-color: #272822\">                                                                </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">            color</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">YELLOW</span><span style=\"background-color: #272822\">                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        )</span><span style=\"background-color: #272822\">                                                                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"background-color: #272822\">                                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"color: #959077; text-decoration-color: #959077; background-color: #272822\"># Add the sine wave path to the scene</span><span style=\"background-color: #272822\">                                                                 </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        self</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">add(sine_wave_path)</span><span style=\"background-color: #272822\">                                                                              </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"background-color: #272822\">                                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"color: #959077; text-decoration-color: #959077; background-color: #272822\"># Animate the circle moving along the sine wave path</span><span style=\"background-color: #272822\">                                                  </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        self</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">play(</span><span style=\"background-color: #272822\">                                                                                            </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">            MoveAlongPath(circle, sine_wave_path, rate_func</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">linear),</span><span style=\"background-color: #272822\">                                          </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">            run_time</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">=</span><span style=\"color: #ae81ff; text-decoration-color: #ae81ff; background-color: #272822\">4</span><span style=\"background-color: #272822\">                                                                                        </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        )</span><span style=\"background-color: #272822\">                                                                                                     </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"background-color: #272822\">                                                                                                      </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        </span><span style=\"color: #959077; text-decoration-color: #959077; background-color: #272822\"># Hold the final position for a moment</span><span style=\"background-color: #272822\">                                                                </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\"> </span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">        self</span><span style=\"color: #ff4689; text-decoration-color: #ff4689; background-color: #272822\">.</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">wait(</span><span style=\"color: #ae81ff; text-decoration-color: #ae81ff; background-color: #272822\">1</span><span style=\"color: #f8f8f2; text-decoration-color: #f8f8f2; background-color: #272822\">)</span><span style=\"background-color: #272822\">                                                                                          </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"background-color: #272822\">                                                                                                               </span> <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m──────────────────────────────────────────────────\u001b[0m\u001b[36m Response \u001b[0m\u001b[36m───────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34mfrom\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mmanim\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34mimport\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m*\u001b[0m\u001b[48;2;39;40;34m                                                                                          \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[48;2;39;40;34m                                                                                                             \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;102;217;239;48;2;39;40;34mclass\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;166;226;46;48;2;39;40;34mCircleSineWave\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mScene\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[48;2;39;40;34m                                                                                 \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m    \u001b[0m\u001b[38;2;102;217;239;48;2;39;40;34mdef\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;166;226;46;48;2;39;40;34mconstruct\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mself\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[48;2;39;40;34m                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;149;144;119;48;2;39;40;34m# Create a circle\u001b[0m\u001b[48;2;39;40;34m                                                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mcircle\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mCircle\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mradius\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m0.2\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mcolor\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mBLUE\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m                                                              \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[48;2;39;40;34m                                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;149;144;119;48;2;39;40;34m# Define the sine wave path\u001b[0m\u001b[48;2;39;40;34m                                                                          \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msine_wave_path\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mParametricFunction\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[48;2;39;40;34m                                                                 \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m            \u001b[0m\u001b[38;2;102;217;239;48;2;39;40;34mlambda\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mt\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m:\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mnp\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34marray\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m[\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mt\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mnp\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msin\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mt\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m0\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m]\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m                                                           \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m            \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mt_range\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mnp\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34marray\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m[\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m-\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mPI\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mPI\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m0.01\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m]\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m                                                               \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m            \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mcolor\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mYELLOW\u001b[0m\u001b[48;2;39;40;34m                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m                                                                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[48;2;39;40;34m                                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;149;144;119;48;2;39;40;34m# Add the sine wave path to the scene\u001b[0m\u001b[48;2;39;40;34m                                                                \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mself\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34madd\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msine_wave_path\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m                                                                             \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[48;2;39;40;34m                                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;149;144;119;48;2;39;40;34m# Animate the circle moving along the sine wave path\u001b[0m\u001b[48;2;39;40;34m                                                 \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mself\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mplay\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[48;2;39;40;34m                                                                                           \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m            \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mMoveAlongPath\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mcircle\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34msine_wave_path\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mrate_func\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mlinear\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m,\u001b[0m\u001b[48;2;39;40;34m                                         \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m            \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mrun_time\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m=\u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m4\u001b[0m\u001b[48;2;39;40;34m                                                                                       \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m                                                                                                    \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[48;2;39;40;34m                                                                                                     \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;149;144;119;48;2;39;40;34m# Hold the final position for a moment\u001b[0m\u001b[48;2;39;40;34m                                                               \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m        \u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mself\u001b[0m\u001b[38;2;255;70;137;48;2;39;40;34m.\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34mwait\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m(\u001b[0m\u001b[38;2;174;129;255;48;2;39;40;34m1\u001b[0m\u001b[38;2;248;248;242;48;2;39;40;34m)\u001b[0m\u001b[48;2;39;40;34m                                                                                         \u001b[0m\u001b[48;2;39;40;34m \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[48;2;39;40;34m                                                                                                               \u001b[0m \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "✅ Generated code: from manim import *\n",
      "\n",
      "class CircleSineWave(Scene):\n",
      "    def construct(self):\n",
      "        # Create a circle\n",
      "        circle = Circle(radius=0.2, color=BLUE)\n",
      "        \n",
      "        # Define the sine wave path\n",
      "      ...\n",
      " Step 2: Validating generated code...\n",
      "📝 Code Summary:\n",
      "   - Scene Name: CircleSineWave\n",
      "   - Syntax Valid: True\n",
      "   - Manim Imports: True\n",
      "   - Scene Class: True\n",
      "   - Code Length: 727 characters\n",
      "   - Lines: 25\n",
      "\n",
      " Generated Code:\n",
      "========================================\n",
      "from manim import *\n",
      "\n",
      "class CircleSineWave(Scene):\n",
      "    def construct(self):\n",
      "        # Create a circle\n",
      "        circle = Circle(radius=0.2, color=BLUE)\n",
      "        \n",
      "        # Define the sine wave path\n",
      "        sine_wave_path = ParametricFunction(\n",
      "            lambda t: np.array([t, np.sin(t), 0]),\n",
      "            t_range=np.array([-PI, PI, 0.01]),\n",
      "            color=YELLOW\n",
      "        )\n",
      "        \n",
      "        # Add the sine wave path to the scene\n",
      "        self.add(sine_wave_path)\n",
      "        \n",
      "        # Animate the circle moving along the sine wave path\n",
      "        self.play(\n",
      "            MoveAlongPath(circle, sine_wave_path, rate_func=linear),\n",
      "            run_time=4\n",
      "        )\n",
      "        \n",
      "        # Hold the final position for a moment\n",
      "        self.wait(1)\n",
      "========================================\n",
      "\n",
      "✅ Code generation complete!\n",
      "🎬 Scene name: CircleSineWave\n",
      "📊 Code quality: 25 lines, 727 characters\n"
     ]
    }
   ],
   "source": [
    "# @title **🚀 Execute Code Generation (FINAL WORKING VERSION)**\n",
    "\n",
    "# Import PraisonAI after setting API key\n",
    "from praisonaiagents import Agent, Task, PraisonAIAgents\n",
    "\n",
    "def generate_manim_code(query: str):\n",
    "    \"\"\"Generate Manim code from user query using PraisonAI\"\"\"\n",
    "    print(f\"🎬 Generating Manim code for: '{query}'\")\n",
    "    print(\"=\" * 60)\n",
    "\n",
    "    # Create agents\n",
    "    manim_agent = Agent(\n",
    "        name=\"Manim Code Generator\",\n",
    "        role=\"Complete Manim Animation Specialist\",\n",
    "        goal=\"Generate high-quality, working Manim code from natural language descriptions\",\n",
    "        backstory=\"Expert Manim developer with deep knowledge of mathematical animations, code generation, debugging, and educational content creation\",\n",
    "        verbose=True,\n",
    "        allow_delegation=False,\n",
    "        tools=[]\n",
    "    )\n",
    "\n",
    "    debugger_agent = Agent(\n",
    "        name=\"Code Debugger\",\n",
    "        role=\"Manim Code Debugger\",\n",
    "        goal=\"Fix errors in Manim code and ensure successful execution\",\n",
    "        backstory=\"Expert in debugging Manim animations and resolving technical issues in mathematical visualization code\",\n",
    "        verbose=True,\n",
    "        allow_delegation=False,\n",
    "        tools=[]\n",
    "    )\n",
    "\n",
    "    # Create tasks\n",
    "    code_generation_task = Task(\n",
    "        description=f\"\"\"\n",
    "        Generate high-quality Manim code for this animation request: {query}\n",
    "\n",
    "        Requirements:\n",
    "        - Create a class that inherits from Scene\n",
    "        - Include proper imports (from manim import *)\n",
    "        - Use descriptive class names\n",
    "        - Include a construct method with self.play() calls\n",
    "        - Add comments for clarity\n",
    "        - Ensure code is complete and runnable\n",
    "        - Follow Manim best practices\n",
    "        - Handle mathematical concepts properly\n",
    "        - Use appropriate animation timing\n",
    "        \"\"\",\n",
    "        agent=manim_agent\n",
    "    )\n",
    "\n",
    "    # Step 1: Generate code\n",
    "    print(\"�� Step 1: Generating Manim code...\")\n",
    "\n",
    "    # Use PraisonAIAgents to execute the task\n",
    "    agents_system = PraisonAIAgents(\n",
    "        agents=[manim_agent],\n",
    "        tasks=[code_generation_task],\n",
    "        verbose=True,\n",
    "        process=\"sequential\"\n",
    "    )\n",
    "\n",
    "    result = agents_system.start()\n",
    "    manim_code = manim_tools.clean_manim_code(result)\n",
    "    print(f\"✅ Generated code: {manim_code[:200]}...\")\n",
    "\n",
    "    # Step 2: Validate code\n",
    "    print(\" Step 2: Validating generated code...\")\n",
    "    code_summary = manim_tools.generate_code_summary(manim_code)\n",
    "\n",
    "    print(f\"📝 Code Summary:\")\n",
    "    print(f\"   - Scene Name: {code_summary['scene_name']}\")\n",
    "    print(f\"   - Syntax Valid: {code_summary['syntax_valid']}\")\n",
    "    print(f\"   - Manim Imports: {code_summary['imports_ok']}\")\n",
    "    print(f\"   - Scene Class: {code_summary['scene_ok']}\")\n",
    "    print(f\"   - Code Length: {code_summary['code_length']} characters\")\n",
    "    print(f\"   - Lines: {code_summary['lines']}\")\n",
    "\n",
    "    # Step 3: Debug if needed\n",
    "    if not code_summary['syntax_valid'] or not code_summary['imports_ok'] or not code_summary['scene_ok']:\n",
    "        print(\"🐛 Step 3: Fixing code issues...\")\n",
    "        issues = []\n",
    "        if not code_summary['syntax_valid']:\n",
    "            issues.append(code_summary['syntax_message'])\n",
    "        if not code_summary['imports_ok']:\n",
    "            issues.append(code_summary['imports_message'])\n",
    "        if not code_summary['scene_ok']:\n",
    "            issues.append(code_summary['scene_message'])\n",
    "\n",
    "        error_msg = \"; \".join(issues)\n",
    "\n",
    "        debug_task = Task(\n",
    "            description=f\"\"\"\n",
    "            Fix these issues in the Manim code:\n",
    "\n",
    "            Code: {manim_code}\n",
    "            Errors: {error_msg}\n",
    "\n",
    "            Provide corrected Manim code that:\n",
    "            - Fixes all syntax errors\n",
    "            - Includes proper Manim imports\n",
    "            - Has a valid Scene class\n",
    "            - Maintains the original animation intent\n",
    "            - Is complete and runnable\n",
    "            \"\"\",\n",
    "            agent=debugger_agent\n",
    "        )\n",
    "\n",
    "        debug_system = PraisonAIAgents(\n",
    "            agents=[debugger_agent],\n",
    "            tasks=[debug_task],\n",
    "            verbose=True,\n",
    "            process=\"sequential\"\n",
    "        )\n",
    "\n",
    "        debug_result = debug_system.start()\n",
    "        manim_code = manim_tools.clean_manim_code(debug_result)\n",
    "\n",
    "        # Re-validate\n",
    "        code_summary = manim_tools.generate_code_summary(manim_code)\n",
    "        print(f\"✅ Debug completed! Code is now valid.\")\n",
    "\n",
    "    return {\n",
    "        \"manim_code\": manim_code,\n",
    "        \"code_summary\": code_summary,\n",
    "        \"scene_name\": code_summary['scene_name']\n",
    "    }\n",
    "\n",
    "def update_manim_code(query: str, existing_code: str):\n",
    "    \"\"\"Update existing Manim code with new requirements\"\"\"\n",
    "    print(f\" Updating Manim code: '{query}'\")\n",
    "    print(\"=\" * 60)\n",
    "\n",
    "    # Create updater agent\n",
    "    updater_agent = Agent(\n",
    "        name=\"Code Updater\",\n",
    "        role=\"Manim Code Updater\",\n",
    "        goal=\"Modify existing Manim animations based on new requirements\",\n",
    "        backstory=\"Specialist in updating and enhancing existing Manim animations while maintaining code quality and functionality\",\n",
    "        verbose=True,\n",
    "        allow_delegation=False,\n",
    "        tools=[]\n",
    "    )\n",
    "\n",
    "    # Create update task\n",
    "    update_task = Task(\n",
    "        description=f\"\"\"\n",
    "        Update this Manim code based on the request:\n",
    "\n",
    "        Original Code: {existing_code}\n",
    "        Update Request: {query}\n",
    "\n",
    "        Provide updated Manim code that:\n",
    "        - Maintains the original structure\n",
    "        - Applies the requested changes\n",
    "        - Keeps the same Scene class\n",
    "        - Ensures code remains runnable\n",
    "        - Preserves existing functionality\n",
    "        \"\"\",\n",
    "        agent=updater_agent\n",
    "    )\n",
    "\n",
    "    # Execute update\n",
    "    print(\"💻 Updating Manim code...\")\n",
    "\n",
    "    update_system = PraisonAIAgents(\n",
    "        agents=[updater_agent],\n",
    "        tasks=[update_task],\n",
    "        verbose=True,\n",
    "        process=\"sequential\"\n",
    "    )\n",
    "\n",
    "    updated_result = update_system.start()\n",
    "    updated_code = manim_tools.clean_manim_code(updated_result)\n",
    "\n",
    "    # Validate updated code\n",
    "    print(\" Validating updated code...\")\n",
    "    code_summary = manim_tools.generate_code_summary(updated_code)\n",
    "\n",
    "    print(f\"📝 Updated Code Summary:\")\n",
    "    print(f\"   - Scene Name: {code_summary['scene_name']}\")\n",
    "    print(f\"   - Syntax Valid: {code_summary['syntax_valid']}\")\n",
    "    print(f\"   - Manim Imports: {code_summary['imports_ok']}\")\n",
    "    print(f\"   - Scene Class: {code_summary['scene_ok']}\")\n",
    "\n",
    "    return {\n",
    "        \"manim_code\": updated_code,\n",
    "        \"code_summary\": code_summary,\n",
    "        \"scene_name\": code_summary['scene_name']\n",
    "    }\n",
    "\n",
    "# Demo execution\n",
    "print(\" AI Manim Code Generator Ready!\")\n",
    "print(\"=\" * 60)\n",
    "\n",
    "# Example usage\n",
    "demo_query = \"Create an animation showing a circle moving in a sine wave pattern\"\n",
    "\n",
    "print(\"🚀 Demo: Generating Manim code...\")\n",
    "result = generate_manim_code(demo_query)\n",
    "\n",
    "print(\"\\n Generated Code:\")\n",
    "print(\"=\" * 40)\n",
    "print(result['manim_code'])\n",
    "print(\"=\" * 40)\n",
    "\n",
    "print(f\"\\n✅ Code generation complete!\")\n",
    "print(f\"🎬 Scene name: {result['scene_name']}\")\n",
    "print(f\"📊 Code quality: {result['code_summary']['lines']} lines, {result['code_summary']['code_length']} characters\")"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
